/*
 * @lc app=leetcode.cn id=189 lang=cpp
 *
 * [189] 轮转数组
 */

// @lc code=start
#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
    void rotate(vector<int> &nums, int k)
    {
        k %= nums.size();

        vector<int> ans;

        auto it = nums.end() - k;
        while (it != nums.end())
        {
            ans.push_back(*it);
            it++;
        }

        it = nums.begin();
        while (it < nums.end() - k)
        {
            ans.push_back(*it);
            it++;
        }

        nums.swap(ans);
        return;
    }
};
// @lc code=end
